<?php
abstract class Component{
    public abstract function operation();
}

class ConcreteComponent extends Component{
    public function operation()
    {
        echo '自己';
    }
}

abstract class Decorator extends Component{
    protected $component;

    public function SetComponent(Component $component){
        $this->component = $component;
    }

    public function operation()
    {
        if(!is_null($this->component)){
            $this->component->operation();
        }
    }
}

class ConcreteDecoratorA extends Decorator{
    private $addedState;
    public function operation()
    {
        parent::operation();
        $this->addedState = 'New state';
        echo 'aa';
    }
}

class ConcreteDecoratorB extends Decorator{
    public function operation()
    {
        parent::operation();
        $this->addedBehavior();

    }

    private function addedBehavior(){
        echo 'bbb';
    }
}

//客户端调用
//$concreateComponent = new ConcreteComponent();
//$concreateDecoratorA = new ConcreteDecoratorA();
//$concreateDecoratorB = new ConcreteDecoratorB();
//
//$concreateDecoratorA->setComponent($concreateComponent);
//$concreateDecoratorB->setComponent($concreateDecoratorA);
//$concreateDecoratorB->operation();

class Person{
    private $name;

    public function __construct(string $name)
    {
        $this->name = $name;
    }

    public function show(){
        echo '装扮的'.$this->name;
    }
}

class Finery extends Person{
    protected $person;
    public function __construct(Person $person)
    {
        $this->person = $person;
    }

    public function show()
    {
        if($this->person != null){
            $this->person->show();
        }
    }
}

class TShirts extends Finery{
    public function show()
    {
        echo 'T恤';
        parent::show();
    }
}

class BigTrouser extends Finery{
    public function show()
    {
        echo '大垮裤';
        parent::show();
    }
}

class Sneakers extends Finery{
    public function show()
    {
        echo '球鞋';
        parent::show();
    }
}

class Suit extends Finery{
    public function show()
    {
        echo '西装';
        parent::show();
    }
}

class Tie extends Finery{
    public function show()
    {
        echo '领带';
        parent::show();
    }
}

//客户端实现
//$person = new Person('韩梅梅');
//$person->init('韩梅梅');

//$suit = new Suit($person);
//$sneakers = new Sneakers($suit);
//$tshirts = new TShirts($sneakers);
//$tshirts->show();
//
//$tshirts->Decorate($person);
//$suit->Decorate($tshirts);
//$sneakers->Decorate($suit);
//$sneakers->show();
//$person->show();
//$tshirts->show();


//网上的例子（自己做过修改） 问题：好像名字无法解决
//abstract class Beverage{
//    public $_name;
//    abstract public function Cost();
//}
//// 被装饰者类
//class Coffee extends Beverage{
//    public function __construct($name){
//        $this->_name = $name;
//    }
//    public function Cost(){
//        return 1.00;
//    }
//}
//// 以下三个类是装饰者相关类
//class CondimentDecorator extends Beverage{
//    public $beverage;
//    public function __construct(Beverage $beverage){
//        $this->beverage = $beverage;
////        $this->_name = $beverage->_name;
//    }
//    public function Cost(){
//        if(!is_null($this->beverage)){
//            return $this->beverage->cost();
//        }
//    }
//}
//
//class Milk extends CondimentDecorator{
//    public function Cost(){
//        return parent::Cost() + 0.2;
//    }
//}
//
//class Sugar extends CondimentDecorator{
//    public function Cost(){
//        return parent::Cost() + 0.3;
//    }
//}
//
//// Test Case
////1.拿杯咖啡
//$coffee = new Coffee('牛奶咖啡加糖');
////2.加点牛奶
//$Milk = new Milk($coffee);
////3.加点糖
////$coffee = new Sugar($coffee);
//
//echo $coffee->_name.':'.$Milk->cost();
//$config = 3;
//$a = $config ?? 1;
//var_dump($a);
//var_dump(json_encode([]));

//echo date('Y-m-d',2100135634);
//function prMonths($start, $end)
//{
//    $dt_start = strtotime($start);
//    $dt_end = strtotime($end);
//    $date = array();
//    while ($dt_start <= $dt_end) {
//        $date[] = date('Y-m', $dt_start);
//        $dt_start = strtotime('+1 Month', $dt_start);
//    }
//    return $date;
//}
//
//$data = prMonths('2017-01-01','2017-05');
//var_dump($data);


//function getthemonth($date)
//{
//    $firstday = date('Y-m-01', strtotime($date));
//    $lastday = date('Y-m-d', strtotime("$firstday +1 month -1 day"));
//    return array($firstday, $lastday);
//}
//var_dump(getthemonth('2017-03'));

//
//function prDates($start, $end)
//{
//    $dt_start = strtotime($start);
//    $dt_end = strtotime($end);
//    $date = array();
//    while ($dt_start <= $dt_end) {
//        $date[] = date('Y-m-d', $dt_start);
//        $dt_start = strtotime('+1 day', $dt_start);
//    }
//    return $date;
//}
//
//var_dump(prDates('2017-11-01','2017-11-01'));

//var_dump(empty(false));
//echo strtotime('-1 Days');
//echo strtotime(date('Y-m-d'));
//echo '####';
//echo  strtotime('2017-10-27 00:00:00');
//echo strtotime('-1 Days 0:0:0');

//echo '123abc' . 1;

//function a($a){
//    foreach($a as $aa){
//        b($aa);
//    }
//}
//
//function b($b){
//
//    if($b==3){
//        return false;
//    }
//    echo $b;
//}
//
//$a = [1,2,3,4,5,6];
//a($a);

//echo date('Y-m-t',strtotime('-1 Months'));
//echo  strtotime('2017-09');

//echo date('Y-m-t',strtotime('2017-2'));
//echo date('Y-m-t 23:59:59',strtotime('2017-09'));
//
//echo  strtotime('2017-09-30 23:59:59');

echo  date('Y-m-d',strtotime('2017-11-08 00:00:00 -1 day'));